package com.study.design.pattern.pattern.behavioral.observer.java;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * @Author: gongsl
 * @Date: 2025-03-23 22:50
 * @description: 被观察者 - StockMarket（股市）
 */
public class StockMarket {
    private double stockPrice;
    private PropertyChangeSupport support;

    public StockMarket() {
        support = new PropertyChangeSupport(this);
    }

    public double getStockPrice() {
        return stockPrice;
    }

    public void setStockPrice(double stockPrice) {
        double oldPrice = this.stockPrice;
        this.stockPrice = stockPrice;
        support.firePropertyChange("stockPrice", oldPrice, stockPrice);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        support.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        support.removePropertyChangeListener(listener);
    }
}
